package com.hctforgreen.greenservice.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 2、所有机型信息
 * @author Tallen Zhai
 *
 */
public class MachineListEntity extends BaseEntity {

	private static final long serialVersionUID = -8254623654417851462L;

	public List<MachineEntity> dataList = null;
	
	public String statusCode = "";
	public String msg = "";
	public final static String STATUS_CODE = "statusCode";
	public final static String MSG = "msg";
	private final static String MACHINES = "machines";
	
	public static MachineListEntity parse(JSONObject jsonObject)throws JSONException{
		MachineListEntity bean = new MachineListEntity();
		if(jsonObject.has(STATUS_CODE)){
			bean.statusCode = jsonObject.getString(STATUS_CODE);
		}
		if(jsonObject.has(MSG)){
			bean.msg = jsonObject.getString(MSG);
		}
		/**
		 * 解析machines节点
		 */
		if (jsonObject.has(MACHINES)) {
			
			JSONArray jsonArray = jsonObject.getJSONArray(MACHINES);
				
			bean.dataList = new ArrayList<MachineEntity>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject object = jsonArray.getJSONObject(i);
				MachineEntity entity = MachineEntity.parse(object);
				bean.dataList.add(entity);
			}
			
		}
		
		return bean;
	}
	public static class MachineEntity extends BaseEntity {

		private static final long serialVersionUID = 689454275024674468L;
		/**
		 * 条码(可能重复)
		 */
		public String barcode = "";
		/**
		 * 名称
		 */
		public String name = "";
		/**
		 * 系列编码
		 */
		public String seriesId = "";
		/**
		 * 子系列编码
		 */
		public String childSeriesId = "";
		/**
		 * id(不会重复)
		 */
		public String id = "";
		public final static String BAR_CODE = "barcode";
		public final static String NAME = "name";
		public final static String SERIES_ID = "seriesId";
		public final static String CHILD_SERIES_ID = "childSeriesId";
		public final static String ID = "id";
		
		public static MachineEntity parse(JSONObject jsonObject)
				throws JSONException {
			MachineEntity bean = new MachineEntity();
			if (jsonObject.has(BAR_CODE)) {
				bean.barcode = jsonObject.getString(BAR_CODE);
			}
			if (jsonObject.has(NAME)) {
				bean.name = jsonObject.getString(NAME);
			}
			if (jsonObject.has(SERIES_ID)) {
				bean.seriesId = jsonObject.getString(SERIES_ID);
			}
			if (jsonObject.has(CHILD_SERIES_ID)) {
				bean.childSeriesId = jsonObject.getString(CHILD_SERIES_ID);
			}
			if (jsonObject.has(ID)) {
				bean.id = jsonObject.getString(ID);
			}
			return bean;
		}
	}
}
